package com.taotao.sso.controller;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.po.TbUser;
import com.taotao.pojo.TaotaoResult;
import com.taotao.sso.service.RegisterService;

@Controller
@RequestMapping("/user")
public class RegisterController {

	@Autowired
	private RegisterService registerService;
	
	@RequestMapping("/check/{param}/{type}")
	@ResponseBody
	public Object registerCheck(@PathVariable String param,@PathVariable Integer type,String callback) throws Exception
	{
		TaotaoResult taotaoResult = registerService.checkData(param, type);
		// 支持jsonp调用
		if (StringUtils.isNoneBlank(callback)) {
			// 请求为jsonp调用，需要支持
			MappingJacksonValue jacksonValue = new MappingJacksonValue(taotaoResult);
			jacksonValue.setJsonpFunction(callback);
			return jacksonValue;
		}
		
		return taotaoResult;
	}
	
	@RequestMapping("/signUp")
	@ResponseBody
	public TaotaoResult registerUser(TbUser user) throws Exception
	{
		TaotaoResult taotaoResult = registerService.register(user);
				
		return taotaoResult;
	}
}
